package com.lwl.service.impl.sds;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lwl.entity.MyPage;
import com.lwl.entity.sds.TSdsPlan;
import com.lwl.service.sds.TSdsPlanService;
import com.lwl.dao.sds.TSdsPlanMapper;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * (TSdsPlan)表服务实现类
 *
 * @author Lei
 * @since 2022-11-09 22:09:04
 */
@Service
public class TSdsPlanServiceImpl implements TSdsPlanService {
   @Autowired
   private TSdsPlanMapper tSdsPlanDao;

   @Override
   public boolean insertPlane(TSdsPlan tSdsPlan) {
      int insert = -1;
      if (tSdsPlan.getId()==null){
//        在这里给实体类赋值对应的创建时间，以及创建者的id
//         Tuser user = (Tuser)session.getAttribute("user");
//         tMhtPlane.setCreatetime(new Date());
//         tMhtPlane.setUid(user.getId());
         insert = tSdsPlanDao.insert(tSdsPlan);
      }else {
         tSdsPlan.setUpdatetime(new Date());
         insert = tSdsPlanDao.updateByPrimaryKeySelective(tSdsPlan);
      }
      return insert>0?true:false;
   }

   @Override
   public boolean selectCode(TSdsPlan tSdsPlan) {
      List<TSdsPlan> select = tSdsPlanDao.select(tSdsPlan);
      return select.size()==0;
   }

   @Override
   public boolean queryByName(String planname) {
      List<TSdsPlan> tSdsPlans = tSdsPlanDao.queryOne(planname);
      return tSdsPlans.size()==0?true:false;
   }

   @Override
   public PageInfo queryAll(MyPage myPage, TSdsPlan tSdsPlan) {
      PageHelper.startPage(myPage.getPage(), myPage.getLimit());
      List<TSdsPlan> tSdsPlanList = tSdsPlanDao.selectAllData(tSdsPlan);
      PageInfo pageInfo = new PageInfo(tSdsPlanList);
      return pageInfo;
   }

   @Override
   public TSdsPlan getByCode(TSdsPlan tSdsPlan) {
      TSdsPlan tSdsPlan1 = tSdsPlanDao.selectOne(tSdsPlan);
      return tSdsPlan1;
   }

   @Override
   public boolean checkPlanId(String planid) {
      TSdsPlan tSdsPlan = tSdsPlanDao.selectByPrimaryKey(planid);
      System.out.println("查到的计划是tMhtPlane = " + tSdsPlan);
      if (tSdsPlan==null){
         return false;
      }else {
         return true;
      }
   }
}
